<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>tests/src/vfs/extfs/helpers-list/misc/rpm/rpm2tags.pl</title>
<meta name='robots' content='noindex,nofollow' />
<meta name='generator' content='GLOBAL-6.5.7' />
<meta http-equiv='Content-Style-Type' content='text/css' />
<link rel='stylesheet' type='text/css' href='../style.css' />
</head>
<body>
<!-- beginning of fixed guide -->
<div id='guide'><ul>
<li><a href='#TOP'><img class='icon' src='../icons/first.png' alt='[^]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/last.png' alt='[v]' /></a></li>
<li><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a></li>
<li><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a></li>
<li><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a></li>
<li class='standout'><span><a href='../files/tests.html'>tests</a>/<a href='../files/tests--src.html'>src</a>/<a href='../files/tests--src--vfs.html'>vfs</a>/<a href='../files/tests--src--vfs--extfs.html'>extfs</a>/<a href='../files/tests--src--vfs--extfs--helpers-list.html'>helpers-list</a>/<a href='../files/tests--src--vfs--extfs--helpers-list--misc.html'>misc</a>/<a href='../files/tests--src--vfs--extfs--helpers-list--misc--rpm.html'>rpm</a>/rpm2tags.pl</span></li>
</ul></div>
<!-- end of fixed guide -->
<a id='TOP' name='TOP'></a><h2 class='header'><a href='../mains.html'>root</a>/<a href='../files/tests.html'>tests</a>/<a href='../files/tests--src.html'>src</a>/<a href='../files/tests--src--vfs.html'>vfs</a>/<a href='../files/tests--src--vfs--extfs.html'>extfs</a>/<a href='../files/tests--src--vfs--extfs--helpers-list.html'>helpers-list</a>/<a href='../files/tests--src--vfs--extfs--helpers-list--misc.html'>misc</a>/<a href='../files/tests--src--vfs--extfs--helpers-list--misc--rpm.html'>rpm</a>/rpm2tags.pl</h2>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><img class='icon' src='../icons/n_first.png' alt='[first]' /><img class='icon' src='../icons/n_last.png' alt='[last]' /><img class='icon' src='../icons/n_top.png' alt='[top]' /><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+1 tests/src/vfs/extfs/helpers-list/misc/rpm/rpm2tags.pl'  /> */</em>
<hr />
<pre>
<a id='L1' name='L1'></a>use strict;
<a id='L2' name='L2'></a>use warnings;
<a id='L3' name='L3'></a>use Data::Dumper;
<a id='L4' name='L4'></a> 
<a id='L5' name='L5'></a>my $help = &lt;&lt;EOF;
<a id='L6' name='L6'></a>WHAT
<a id='L7' name='L7'></a>----
<a id='L8' name='L8'></a> 
<a id='L9' name='L9'></a>This script converts an RPM package into what we call a "tags file",
<a id='L10' name='L10'></a>which is simply an associative array listing all the tags and their
<a id='L11' name='L11'></a>values.
<a id='L12' name='L12'></a> 
<a id='L13' name='L13'></a>WHY
<a id='L14' name='L14'></a>---
<a id='L15' name='L15'></a> 
<a id='L16' name='L16'></a>For our rpm helper tests we need an RPM file. But we also want the tests
<a id='L17' name='L17'></a>to be able to run on systems where the rpm binary isn't installed. The
<a id='L18' name='L18'></a>solution: our tests work on "tags files" instead of real RPM files.
<a id='L19' name='L19'></a> 
<a id='L20' name='L20'></a>HOW
<a id='L21' name='L21'></a>---
<a id='L22' name='L22'></a> 
<a id='L23' name='L23'></a>Use it like this:
<a id='L24' name='L24'></a> 
<a id='L25' name='L25'></a>    \$ perl $0 /path/to/some/package.rpm &gt; test.input
<a id='L26' name='L26'></a> 
<a id='L27' name='L27'></a>You can run this script only on systems where 'rpm' is installed.
<a id='L28' name='L28'></a> 
<a id='L29' name='L29'></a>WHEW
<a id='L30' name='L30'></a>----
<a id='L31' name='L31'></a> 
<a id='L32' name='L32'></a>After all was done the author of this script discovered something not
<a id='L33' name='L33'></a>mentioned in rpm's manpage: one can do "rpm -qp --xml pkg.rpm" to
<a id='L34' name='L34'></a>serialize the metadata and get the same effect. But this would just move
<a id='L35' name='L35'></a>the complexity to the test (in handling XML).
<a id='L36' name='L36'></a>EOF
<a id='L37' name='L37'></a> 
<a id='L38' name='L38'></a># Tag variations we're interested in and wish to record as well.
<a id='L39' name='L39'></a>my @formatted_tags = qw(
<a id='L40' name='L40'></a>  BUILDTIME:date
<a id='L41' name='L41'></a>  CHANGELOGTIME:date
<a id='L42' name='L42'></a> 
<a id='L43' name='L43'></a>  REQUIREFLAGS:depflags
<a id='L44' name='L44'></a>  PROVIDEFLAGS:depflags
<a id='L45' name='L45'></a>  OBSOLETEFLAGS:depflags
<a id='L46' name='L46'></a>  CONFLICTFLAGS:depflags
<a id='L47' name='L47'></a>);
<a id='L48' name='L48'></a> 
<a id='L49' name='L49'></a># Big tags we want to omit to save space.
<a id='L50' name='L50'></a>my %skip = map {$_ =&gt; 1} qw(
<a id='L51' name='L51'></a>  HEADERIMMUTABLE
<a id='L52' name='L52'></a>);
<a id='L53' name='L53'></a> 
<a id='L54' name='L54'></a># Make 'rpm' print dates in the format our helper expects.
<a id='L55' name='L55'></a>$ENV{'LC_TIME'} = 'C';
<a id='L56' name='L56'></a> 
<a id='L57' name='L57'></a>sub rpm2tags
<a id='L58' name='L58'></a>{
<a id='L59' name='L59'></a>  my ($rpm_pkg) = @_;
<a id='L60' name='L60'></a> 
<a id='L61' name='L61'></a>  my %tags = ();
<a id='L62' name='L62'></a> 
<a id='L63' name='L63'></a>  chomp(my @all_tags = `rpm --querytags`);
<a id='L64' name='L64'></a>  @all_tags = grep {!$skip{$_}} @all_tags;
<a id='L65' name='L65'></a> 
<a id='L66' name='L66'></a>  foreach my $tag (@all_tags, @formatted_tags) {
<a id='L67' name='L67'></a>    $tags{$tag} = `rpm -qp --qf "%{$tag}" "$rpm_pkg"`;
<a id='L68' name='L68'></a>  }
<a id='L69' name='L69'></a> 
<a id='L70' name='L70'></a>  # Add pseudo tags:
<a id='L71' name='L71'></a>  $tags{'_INFO'} = `rpm -qip "$rpm_pkg"`;
<a id='L72' name='L72'></a> 
<a id='L73' name='L73'></a>  return %tags;
<a id='L74' name='L74'></a>}
<a id='L75' name='L75'></a> 
<a id='L76' name='L76'></a>sub prolog
<a id='L77' name='L77'></a>{
<a id='L78' name='L78'></a>  my $cmdline = join(' ', 'perl', $0, @ARGV);
<a id='L79' name='L79'></a>  return &lt;&lt;EOF;
<a id='L80' name='L80'></a># -*- mode: perl -*-
<a id='L81' name='L81'></a># vim: filetype=perl
<a id='L82' name='L82'></a>#
<a id='L83' name='L83'></a># This "tags file" was created by running the following command:
<a id='L84' name='L84'></a>#
<a id='L85' name='L85'></a>#    \$ $cmdline
<a id='L86' name='L86'></a>#
<a id='L87' name='L87'></a># This file is used in our tests instead of the corresponding RPM file.
<a id='L88' name='L88'></a># This lets us run the tests on systems where 'rpm' is not installed.
<a id='L89' name='L89'></a>EOF
<a id='L90' name='L90'></a>}
<a id='L91' name='L91'></a> 
<a id='L92' name='L92'></a>sub main
<a id='L93' name='L93'></a>{
<a id='L94' name='L94'></a>  if (!$ARGV[0] || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
<a id='L95' name='L95'></a>    print $help;
<a id='L96' name='L96'></a>    exit;
<a id='L97' name='L97'></a>  }
<a id='L98' name='L98'></a>  my %tags = rpm2tags($ARGV[0]);
<a id='L99' name='L99'></a>  $Data::Dumper::Terse = 1;
<a id='L100' name='L100'></a>  print(prolog(), "\n", '$tags = ', Dumper(\%tags), ";\n");
<a id='L101' name='L101'></a>}
<a id='L102' name='L102'></a> 
<a id='L103' name='L103'></a>main();
</pre>
<hr />
<a id='BOTTOM' name='BOTTOM'></a>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><img class='icon' src='../icons/n_first.png' alt='[first]' /><img class='icon' src='../icons/n_last.png' alt='[last]' /><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a><img class='icon' src='../icons/n_bottom.png' alt='[bottom]' /><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+103 tests/src/vfs/extfs/helpers-list/misc/rpm/rpm2tags.pl'  /> */</em>
</body>
</html>
